<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      div {
        position: absolute;
        left: 0;
        width: 100px;
        height: 100px;
        background-color: pink;
      }
    </style>
  </head>

  <body>
    <div></div>
    <script>
      let div = document.querySelector("div");
      let startX = 0;
      let startY = 0;
      let x = 0;
      let y = 0;

      div.addEventListener("touchstart", function (event) {
        startX = event.targetTouches[0].pageX;
        startY = event.targetTouches[0].pageY;
        x = this.offsetLeft;
        y = this.offsetTop;
      });

      div.addEventListener("touchmove", function (event) {
        // 计算手指的移动距离:手指移动之后的坐标减去手指初始的坐标
        let moveX = event.targetTouches[0].pageX - startX;
        let moveY = event.targetTouches[0].pageY - startY;
        this.style.left = x + moveX + "px";
        this.style.top = y + moveY + "px";
      });
    </script>
  </body>
</html>
